<template>
	<view class="bg min100 pb-10">
		<u-sticky>
			<view class="bg-blue white">
				<u-tabs v-if="tabList.length>1" :list="tabList" font-size="32" bg-color="#120062" height="90" active-color="#fff" inactive-color="#eee"
				 :is-scroll="false" :current="index" @change="change"></u-tabs>
			</view>
		</u-sticky>
		<view class="pd-30">
			<empty v-if="list.length==0" text="暂无订单"></empty>
			<view v-for="(item,i) in list" :key="i" class="mb-30">
				<orderItem v-if="current==0" :type="3" :item="item"></orderItem>
				<sfItem v-if="current==1" type="3" :item="item"></sfItem>
				<hyItem v-if="current==2" type="3" :item="item"></hyItem>
			</view>
			<u-loadmore v-show="list.length>9" :status="status" icon-type="flower" bg-color="transperant" margin-top="30"
			 margin-bottom="30" />
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				index:0,
				current: '',
				timer3: null,
				page: 1,
				status: 'loadmore',
				list: [],
			}
		},
		onLoad() {
			this.timer3 = setInterval(()=>{
				if(this.tabList&&this.tabList[0]){
					this.current = this.tabList[0].id
					this.getList()
					clearInterval(this.timer3)
					this.timer3 = null
				}
			},200)
		},
		onUnload() {
			clearInterval(this.timer3)
		},
		onHide() {
			clearInterval(this.timer3)
		},
		computed: {...mapState(['tabList'])},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.getList()
		},
		methods: {
			change(index) {
				this.index = index;
				this.current = this.tabList[index].id;
				this.page = 1
				this.list = []
				this.status = 'loadmore'
				this.getList()
			},
			getList() {
				this.status = "loading";
				if(this.current==2){
					this.$http('/addons/ddrive/hyorder/order_list', {
							type: 2,
						}, "POST").then(res => {
							let data = res.data
							if (data.length < 10) {
								this.status = "nomore"
							} else {
								this.page = this.page + 1
								this.status = "loadmore"
							}
							this.list = this.list.concat(data)
							uni.stopPullDownRefresh();
						})
					
				}else{
					this.$http(this.current==0?'/addons/ddrive/order/order_info':'/addons/ddrive/sforder/user_order', {
							order_type: 2,
						}, "POST").then(res => {
							let data = this.current==0?res.data:res
							if (data.length < 10) {
								this.status = "nomore"
							} else {
								this.page = this.page + 1
								this.status = "loadmore"
							}
							this.list = this.list.concat(data)
							uni.stopPullDownRefresh();
						})
					
				}
			},

		}

	}
</script>

<style scoped lang="scss">

</style>
